package com.zhu.day.learn2023;

import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

//https://juejin.cn/post/6844904022344744967
//链表反转
public class LinkReverse {

    @Data
    @NoArgsConstructor
    public static class Node {
        //链表用于存储值
        private int value;
        //指向下一个节点 理解为Node next更加恰当
        private Node node;

        public Node(int value) {
            this.value = value;
        }
    }


    public static Node reverserLinkedList(Node node) {
        //指向空，可以想象成位于第一个节点之前
        Node newNode = null;
        //指向第一个节点
        Node curNode = node;
        //循环中，使用第三变量事先保存curNode的后面一个节点
        while (curNode != null) {
            Node tempNode = curNode.getNode();
            //把curNode反向往前指
            curNode.setNode(newNode);
            //newNode向后移动
            newNode = curNode;
            //curNode 向后移动
            curNode = tempNode;
        }
        return newNode;
    }


    public static void main(String[] args) {
//        List<Integer> list = new ArrayList<>();
//        for (int i = 0; i < 10; i++) {
//            list.add(i);
//        }
//        Node linkedList = createLinkedList(list);
//        printList(linkedList);
//        Node node = reverserLinkedList(linkedList);
//        printList(node);


        System.out.println("现在花销(6000+1350+3334+3000)*12="+(6000+1350+3334+3000)*(12)+"元");
        System.out.println("去掉车贷(6000+1350+3000)*12="+(6000+1350+3000)*(12)+"元");
        System.out.println("再去掉房租(1350+3000)*12="+(1350+3000)*(12)+"元");

        boolean numeric = StringUtils.isNumeric("40012345");
        System.out.println(numeric);


    }


    //测试方便的打印函数
    public static void printList(Node node) {
        while (node != null) {
            System.out.print(node.getValue());
            System.out.print(" ");
            node = node.getNode();
        }
        System.out.println();
        System.out.println("-----------------");
    }

    //构建函数
    public static Node createLinkedList(List<Integer> list) {
        if (list.isEmpty()) {
            return null;
        }
        Node headNode = new Node(list.get(0));
        Node tempNode = createLinkedList(list.subList(1, list.size()));
        headNode.setNode(tempNode);
        return headNode;
    }
}
